<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    div.loading {
      width: 80px;
      height: 80px;
      background: red;
      color: white;
      display: none;
    }
  </style>
</head>
<body>
  <div id="loading" class="loading">loading</div>
  <script src="js/03-ajax.js"></script>
  <script>
    const promise = new Promise((resolve, reject) => {
      resolve('成功')
      // reject('失败')
    }).then(msg => {
      console.log('resolve')
    }).catch(error => {
      console.log(error)
    }).finally(() => {
      console.log('永远会执行')
    })

    ajax('http://localhost:3000/posts').then(value => {
      console.log(value)
    }).catch(err => {
      console.log(err)
    }).finally(() => {
      loading.style.display = 'none'
    })
  </script>
</body>
</html>